package com.bdqn.ch10.controller;

import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(UnauthorizedException.class)
    public ModelAndView unauthorizedExceptionHandler(HttpServletRequest request , UnauthorizedException e){
        ModelAndView mv = new ModelAndView("403");
        mv.addObject("exception" , e);
        mv.addObject("url" , request.getRequestURL());

        return mv;
    }
}
